package com.metaboot.demo.controller;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.metaboot.common.annotation.Log;
import com.metaboot.common.annotation.RepeatSubmit;
import com.metaboot.common.core.controller.BaseController;
import com.metaboot.common.core.domain.AjaxResult;
import com.metaboot.common.core.page.TableDataInfoPlus;
import com.metaboot.common.enums.BusinessType;
import com.metaboot.common.utils.poi.ExcelUtil;
import com.metaboot.demo.domain.DemoSingle;
import com.metaboot.demo.service.IDemoSingleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 单表演示Controller
 * 
 * @author theodo
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/demo/single")
@Api(value = "单表演示控制器", tags = {"单表演示"})
public class DemoSingleController extends BaseController {
    @Autowired
    private IDemoSingleService demoSingleService;

    /**
     * 查询单表演示列表
     */
    @ApiOperation("查询单表演示列表")
    @PreAuthorize("@ss.hasPermi('demo:single:list')")
    @GetMapping("/list")
    public TableDataInfoPlus<DemoSingle> list(DemoSingle demoSingle){
    	return demoSingleService.selectPageDemoSingleList(demoSingle);
    }
    
    /**
     * 查询单表演示列表-自定义分页
     */
    @ApiOperation("查询单表演示列表-自定义分页")
    @PreAuthorize("@ss.hasPermi('demo:single:list')")
    @GetMapping("/listMulti")
    public TableDataInfoPlus<DemoSingle> listMulti(DemoSingle demoSingle){
    	return demoSingleService.selectMultiPageDemoSingleList(demoSingle);
    }

    /**
     * 导出单表演示列表
     */
    @ApiOperation("导出单表演示列表")
    @PreAuthorize("@ss.hasPermi('demo:single:export')")
    @Log(title = "单表演示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoSingle demoSingle) {
        List<DemoSingle> list = demoSingleService.selectDemoSingleList(demoSingle);
        ExcelUtil<DemoSingle> util = new ExcelUtil<DemoSingle>(DemoSingle.class);
        util.exportExcel(response, list, "单表演示数据");
    }

    /**
     * 获取单表演示详细信息
     */
    @ApiOperation("获取单表演示详细信息")
    @PreAuthorize("@ss.hasPermi('demo:single:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(demoSingleService.selectDemoSingleById(id));
    }

    /**
     * 新增单表演示
     */
    @ApiOperation("新增单表演示")
    @PreAuthorize("@ss.hasPermi('demo:single:add')")
    @Log(title = "单表演示", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit()
    public AjaxResult add(@RequestBody DemoSingle demoSingle) {
        return toAjax(demoSingleService.insertDemoSingle(demoSingle));
    }

    /**
     * 修改单表演示
     */
    @ApiOperation("修改单表演示")
    @PreAuthorize("@ss.hasPermi('demo:single:edit')")
    @Log(title = "单表演示", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit()
    public AjaxResult edit(@RequestBody DemoSingle demoSingle) {
        return toAjax(demoSingleService.updateDemoSingle(demoSingle));
    }

    /**
     * 删除单表演示
     */
    @ApiOperation("删除单表演示")
    @PreAuthorize("@ss.hasPermi('demo:single:remove')")
    @Log(title = "单表演示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(demoSingleService.deleteDemoSingleByIds(Arrays.asList(ids)));
    }
}
